n=int(input())
M=0
if 999<n<10000:
     n1=n
     n2=n//10
     n3=n//100
     n4=n//1000
     n5=n%1000
     n6=n%1000//10
     n7=n%1000//100
     n8=n%100
     n9=n%100//10
     n10=n%10
     S=[n1,n2,n3,n4,n5,n6,n7,n8,n9,n10]
     for y in S:
          k=0
          for i in range (1,y//2+1):
               if y%i==0:
                    k=k+1
          if k==1:
               M=max(M,y)
     print(M)
else:
     print("0")
